#include <iostream>

#include "engine.h"
#include "internal_types.h"
#include "comp_mgr.h"

using namespace std;
using namespace HW;

int main()
{
	if ( !Initialize ( ) )
	{
		cout << "Failed to initialize engine." << endl;
		return 0;
	}

	SetAppTitle ( "asbe abi!" );

	if ( !Graphics ( 1280 , 720 , 0 ) )
	{
		cout << "Failed to create window." << endl;
		return 0;
	}

	cout << GraphicsWidth() << " * " << GraphicsHeight() << endl;

	cout << GraphicsModeExists ( 700 , 600 , 0 , 10 ) << endl;

	cout << GetGraphicsVendor() << endl;

	AppLog ( AbstractPath ( "abstract::simple.vert" ) );
	char ch[10];
	_itoa_s(MaxColorBuffers(),ch,10);
	AppLog ( ch );

	TTexture raftex = LoadTexture ( "abstract::raf22031.dds" );

	TBuffer gbuf[2];
	for ( int i = 0 ; i < 2 ; i ++ )
		gbuf[i] = CreateBuffer ( GraphicsWidth()/(i+1) , GraphicsHeight()/(i+1) , BUFFER_COLOR0|BUFFER_COLOR1|BUFFER_COLOR2|BUFFER_COLOR3|BUFFER_DEPTH );
	/*SetColorBuffer ( gbuf , CreateTexture() , 2 );
	SetColorBuffer ( gbuf , CreateTexture() , 2 );
	SetColorBuffer ( gbuf , CreateTexture() , 2 );
	SetColorBuffer ( gbuf , CreateTexture() , 2 );
	SetColorBuffer ( gbuf , CreateTexture() , 2 );
	SetColorBuffer ( gbuf , CreateTexture() , 2 );*/

	TShader ablahSh = LoadShader ( "abstract::simple.vert" , "abstract::normal.frag" );
	SetShader ( NULL );

	LoadMaterial ( "abstract::loft_brick_white.mat" );
	CreateMaterial();

	CreateBuffer();

	while ( !KeyHit() && !AppTerminate() )
	{
		if ( !AppSuspended() )
		{
		UpdateAppTime();
		if ( MouseZ() > 0 )
			PauseApp();
		else if ( MouseZ() < 0 )
			ResumeApp();
		int asb = GetChar ( );
		if ( asb != 0 )
		{
			char ch[14] = "khare baldar";
			ch[12] = asb;
			ch[13] = NULL;
			AppLog ( ch );
		}
		/*for ( int i = 0 ; i < 1 ; i ++ )
		{
			SetBuffer ( gbuf[i] );
			ClearBuffer();
		}
		if ( KeyDown() )
		CopyBuffer ( gbuf[0] , BackBuffer() , BUFFER_DEPTH );
		SetBuffer ( BackBuffer() );*/
		ClearBuffer();

		DrawImage ( raftex , 0 , 0 , MouseX() , MouseY() );
		
		//cout << KeyHit ( KEY_BACKSPACE ) << endl;
		Flip ( 0 );
		}
	}
	cout << sizeof(HW::ComponentManager::CompRegData) << endl;

	return Terminate();
}